package jmine.tec.proxy.cglib;

import java.lang.reflect.Method;

import jmine.tec.proxy.chain.ChainElement;
import jmine.tec.proxy.chain.DelegatingInvocationChain;
import net.sf.cglib.proxy.MethodProxy;

/**
 * InvocationChain que usa o CGLIB
 * 
 * @author takeshi
 * 
 */
public class CGLIBInvocationChain extends DelegatingInvocationChain {

    private final MethodProxy fastMethod;

    /**
     * C'tor
     * 
     * @param delegate
     *            the deleagate object
     * @param el
     *            the ChainElements
     * @param method
     *            the {@link Method}
     * @param proxy
     *            the proxy objecton witch the method was originally invoked
     * @param args
     *            the arguments
     * @param methodProxy
     *            the {@link MethodProxy} from cglib
     */
    public CGLIBInvocationChain(final Object delegate, final ChainElement[] el,
            final Method method, final Object proxy, final Object[] args,
            final MethodProxy methodProxy) {
        super(delegate, el, method, proxy, args);
        this.fastMethod = methodProxy;
    }

    /**
     * @return Object
     * @throws Throwable
     *             t
     * @see br.com.maps.util.proxy.chain.DelegatingInvocationChain#invokeEndOfChain()
     */
    @Override
    protected Object invokeEndOfChain() throws Throwable {
        return this.fastMethod.invoke(this.getBean(), this.getParams());
    }

    /**
     * @return the fastMethod
     */
    protected final MethodProxy getFastMethod() {
        return fastMethod;
    }
}
